package com.jinbo.footmessageworker.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * 基于SharedPreferences的本地缓存工具类，用于缓存一些HTTP数据等
 * @author fangjinbo
 *
 */
public class LocalPreferencesHelper {
    private SharedPreferences mSharedPreferences;
    public static String DB_NAME = "FootMessageWorker";


    public static String USER_PASSWORD ="worker_password"; //用户密码
    public static String USER_ID = "worker_id"; //用户id
    public static String USER_MOBILE = "worker_mobile"; //用户手机
    public static String USER_NAME= "worker_name"; //用户名
    public static String USER_HEAD_URL= "worker_head_url";//下载地址
    public static String USER_SEX= "worker_sex";
    public static String USER_MAIl= "worker_mail";
    public static String USER_NICKNAME= "worker_nickname";
    public static String USER_AGE= "worker_age";
    public static String USER_SPECIALITY= "worker_speciality";

    public static String REMARK_CUSTOMER= "REMARK_CUSTOMER";
    public static String REMARK_TIME_CUSTOMER= "REMARK_TIME_CUSTOMER";
    public static String REMARK_TIME_WORKER= "REMARK_TIME_WORKER";
    public static String  REMARK_WORKER="REMARK_WORKER";


    public static String  G0_OUT_SERVER="G0_OUT_SERVER";//完成 1：签出 2：签回
    public static String  G0_OUT_TIME="G0_OUT_TIME";
    public LocalPreferencesHelper(Context context, String dbName) {
        mSharedPreferences = context.getSharedPreferences(dbName,
                Context.MODE_PRIVATE);
    }

    public void saveOrUpdate(String key, String value) {
        mSharedPreferences.edit().putString(key, value).commit();
    }

    public void saveOrUpdate(String key, int value) {
        mSharedPreferences.edit().putInt(key, value).commit();
    }

    public void saveOrUpdate(String key, float value) {
        mSharedPreferences.edit().putFloat(key, value).commit();
    }

    public void saveOrUpdate(String key, boolean value) {
        mSharedPreferences.edit().putBoolean(key, value).commit();
    }

    public void saveOrUpdate(String key, long value) {
        mSharedPreferences.edit().putLong(key, value).commit();
    }

    public void del(String key) {
        mSharedPreferences.edit().remove(key).commit();
    }

    public float getFloat(String key) {
        return mSharedPreferences.getFloat(key, -1);
    }

    public String getString(String key) {
        return mSharedPreferences.getString(key, "");
    }

    public boolean getBooleanDefaultFalse(String key) {
        return mSharedPreferences.getBoolean(key, false);
    }

    public boolean getBooleanDefaultTrue(String key) {
        return mSharedPreferences.getBoolean(key, true);
    }

    public int getInt(String key) {
        return mSharedPreferences.getInt(key, -1);
    }

    public int getInt(String key, int defValue) {
        return mSharedPreferences.getInt(key, defValue);
    }

    public long getLong(String key) {
        return mSharedPreferences.getLong(key, -1);
    }

    public long getLong(String key, long defValue) {
        return mSharedPreferences.getLong(key, defValue);
    }

}
